package cn.fx.web.controller;

import cn.fx.service.IMovieTicketService;
import cn.fx.domain.MovieTicket;
import cn.fx.query.MovieTicketQuery;
import cn.fx.result.JsonResult;
import cn.fx.result.PageList;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/movieTicket")
public class MovieTicketController {

    @Autowired
    public IMovieTicketService movieTicketService;

    /**
    * 保存和修改公用的
    */
    @RequestMapping(value="/save",method= RequestMethod.POST)
    public JsonResult saveOrUpdate(@RequestBody MovieTicket movieTicket){
        if(movieTicket.getId()!=null){
            movieTicketService.updateById(movieTicket);
        }else{
            movieTicketService.insert(movieTicket);
        }
        return JsonResult.success();
    }

    /**
    * 查询所有对象
    */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResult list(){
        return JsonResult.success(movieTicketService.selectList(null));
    }

    /**
     *  根据用户id和电影查询
     */
    @GetMapping("/buy/{userId}/{movieId}")
    public JsonResult buy(@PathVariable("userId") Long userId, @PathVariable("movieId") Long movieId){
        return movieTicketService.buy(userId, movieId);
    }

    /**
     * 根据用户id和电影查询
     */
    @GetMapping("/watch/{userId}/{movieId}")
    public JsonResult watch(@PathVariable("userId") Long userId, @PathVariable("movieId") Long movieId){
        return movieTicketService.expiration(userId, movieId);
    }
}
